package com.item.service.impl;

import com.item.bean.Result;
import com.item.bean.UserName;
import com.item.domain.TUsers;
import com.item.mapper.PcUserNameMapper;
import com.item.po.TUsersPo;
import com.item.service.PcUserNameService;
import com.item.utils.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class PcUserNameServiceImpl implements PcUserNameService {

    @Autowired
    PcUserNameMapper pcUserNameMapper;

    @Override
    public Result loginUser(TUsers userName) {

        Result result = new Result();
        result.setFlag(false);
        result.setData(null);
        System.out.println("服务端打印对象" + userName);
        System.out.println("服务端拿到手机号" + userName.getTelePhone());
        System.out.println("服务端拿到密码" + userName.getPassWord());
        userName.setPassWord(MD5Utils.md5(userName.getPassWord()));
        System.out.println("服务端拿到加密后的密码" + userName.getPassWord());
        //获取用户名,这里是调用mapper层的getUsername来判断是否正确
        TUsersPo userByName = pcUserNameMapper.selectFindAll(userName);
        userByName.setPassWord("");
        System.out.println("打印判断登录查询返回的结果" + userByName);

        //判断数据查询成功
        if (userByName != null) {
            result.setMessage("登录成功");
            result.setFlag(true);
            result.setData(userByName);
        } else {
            result.setMessage("用户名或密码错误");
            result.setFlag(false);
        }
        return result;
    }
}
